<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<script>
    var fb = function(n) {
        if(n<=1)return 1;
        return n*fb(n-1);
    }
    console.log('fb:',fb(5));

    var fb2= function (n) {
        return [1][n] || n*fb2(n-1);
    };
    console.log('fb2:',fb2(5));

    var fb3= function (n, self) {
        return [1][n] || n*self(n-1,self);
    };
    console.log('fb3:',fb3(5,fb3));

    var fb4= function (self) {
        return function (n) {
            return [1][n] || n*self(self)(n-1);
        }
    };
    console.log('fb4:',fb4(fb4)(5));





    var Y = function(f) {
        return (function(g) {
            return g(g);
        })(function(h) {
            return f(function() {
                return h(h).apply(null, arguments);
            });
        });
    };


    function f(n){
        return f2(n,1,1);
    }

    function f2(n,i,result){
        console.log(arguments);
        if(i>n)return result;
        return f2(n,i+1,result*i);
    }

    console.log('Tail:',f(3));


</script>
</body>
</html>